/*
 * @lc app=leetcode.cn id=746 lang=typescript
 *
 * [746] 使用最小花费爬楼梯
 */

// @lc code=start

// TODO 动态规划 = 滚雪球
// 求出状态累加方程，然后通过累加变换得到最终状态
function minCostClimbingStairs(cost: number[]): number {
    let costTotal = [cost[0]];
    for (let index = 1; index < cost.length; index++) {
        const a0 = costTotal[index - 2] || 0;
        const a1 = costTotal[index - 1];
        const a2 = cost[index];
        const min = Math.min(a0, a1);
        costTotal[index] = min + a2;
    }
    return Math.min(
        costTotal[costTotal.length - 1],
        costTotal[costTotal.length - 2]
    );
}
// @lc code=end
